--
-- Author: shunguo.chen
-- Date: 2018-07-04 17:07:42
--
-- MountSoul 坐骑灵魂石

local MountSoul = class("MountSoul")

local string_ulen = string.ulen
local string_usub = string.usub

-- 坐骑灵魂石道具名字显示最大字符，多余的需要截取加...
local SHOW_NAME_MAX_LEN = Constant.ITEM_SHOW_NAME_MAX_LEN

function MountSoul:ctor()
	self.itemBagType = Enums.ItemBagType.mountSoul

	self.id = 0
	self.num = 0
end

function MountSoul:isValid()
	return self.conf ~= nil
end

function MountSoul:read(value)
	self.id = value.id
	self.num = value.num

	self.conf = GD:getMountSoulConf(self.id)
	assert(self.conf ~= nil, "MountSoul.conf can't be nil " .. self.id)

	self.quality = tonumber(self.conf.quality or 4)
end

function MountSoul:getAmount()
	return self.num
end

-- isFull true/false 是否取全名
-- maxLen number 自定义截取最大字数
-- 名字默认按6个utf8字符计算，多于6个的截取5个加...
function MountSoul:getName(isFull, maxLen)
	isFull = isFull or false
	if isFull then
		return L(self.conf.name)
	else
		if maxLen and maxLen ~= SHOW_NAME_MAX_LEN then
			local name = L(self.conf.name)
			local len = string_ulen(name)
			if len > maxLen then
				return string_usub(name, 1, maxLen-1) .. "..."
			else
				return name
			end
		else
			if not self._showName then
				local name = L(self.conf.name)
				local len = string_ulen(name)
				if len > SHOW_NAME_MAX_LEN then
					self._showName = string_usub(name, 1, SHOW_NAME_MAX_LEN-1) .. "..."
				else
					self._showName = name
				end
			end
			return self._showName
		end
	end
end

function MountSoul:getDesc()
	return L(self.conf.des)
end

-- 类型名字
function MountSoul:getTypeName()
	local showType = self.conf.showType or Enums.ItemShowType.mount
	return L(Res.showTypeName .. showType)
end

function MountSoul:getQuality()
	return self.quality
end

function MountSoul:getIconBg()
	return Res.Qulity_Icon_Bg[self.quality]
end

function MountSoul:getIcon()
	return string.format("%s%s.png", Res.itemPath, self.conf.icon)
end

function MountSoul:getResource()
	local resource = GD:getConvertResource(self.conf.getResource, Enums.ItemBagType.mountSoul, tonumber(self.conf.ID))
	return resource
end

return MountSoul